package com.example.constellation.Activity;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.TextView;

import com.example.constellation.R;

public class welcomeActivity extends AppCompatActivity {
    private TextView welcometv;
    private int count=5;
    Handler handler=new Handler(){
        @Override
        public void handleMessage(@NonNull Message msg) {
            if (msg.what==2) {
                count--;
                if (count==0){
                    //判断是否第一次进入
                    boolean isfirst = first.getBoolean("isfirst", true);
                    Intent intent=new Intent();
                    if (isfirst) {
                     intent.setClass(welcomeActivity.this, GuideActivity.class);
                        SharedPreferences.Editor edit = first.edit();
                        edit.putBoolean("isfirst",false);
                        edit.commit();
                    }else {
                        intent.setClass(welcomeActivity.this, MainActivity.class);
                    }
                    startActivity(intent);
                    finish();
                }else {
                    welcometv.setText(String.valueOf(count));
                    handler.sendEmptyMessageDelayed(2,500);
                }
            }
        }
    };
    private SharedPreferences first;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);
        welcometv=findViewById(R.id.welcometv);
        //判断是否第一次进入
        first = getSharedPreferences("first", MODE_PRIVATE);
        handler.sendEmptyMessageDelayed(2,500);
    }
}
